<%@page pageEncoding="utf-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>车位使用管理</title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/x-layui.js" charset="utf-8"></script>

    <script>
        layui.use(['laydate','element','laypage','layer'], function(){});
    </script>

    <style>
        #a{
            display:inline-block;
            margin-left: 30px;
        }
    </style>

</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>停车位管理</cite></a>
              <a><cite>车位使用列表</cite></a>
            </span>

</div>

<div class="x-body">

    <xblock>
        <button class="layui-btn" onclick="parkinguse_add('添加数据',
                '${pageContext.request.contextPath}/parkinguse/addUi','1000','600')">
            <i class="layui-icon">&#xe608;</i>&nbsp;&nbsp;添加数据
        </button>

        <form id="a" action="${pageContext.request.contextPath}/parkinguse/select" method="post" style="width:800px">
            <div class="layui-input-inline">
                <input type="text" name="vname"  placeholder="请输入小区名称" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline" style="width:80px">
                <button type="submit" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </form>

        <button class="layui-btn x-right" style="margin-left: 10px;"
                onclick="javascript:location.replace(location.href);">
            <i class="layui-icon">ဂ</i>&nbsp;&nbsp;刷新
        </button>

        <span class="x-right" style="line-height:40px">共有数据：
            <span class="layui-badge">${parkinguseTotal.size()}</span> 条
        </span>
    </xblock>

    <table class="layui-table">
        <thead>
        <tr>
            <th>序号</th>
            <th>编号</th>
            <th>所属小区</th>
            <th>车位名称</th>
            <th>车牌号码</th>
            <th>车辆牌照</th>
            <th>车辆所有人姓名</th>
            <th>联系方式</th>
            <th>使用性质</th>
            <th>总费用(￥)</th>
            <th>开始时间</th>
            <th>截止时间</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody>
        <c:forEach items="${parkinguses}" var="parkinguse" varStatus="status">
            <tr>
                <td>${status.index + 1}</td>
                <td>${parkinguse.id}</td>
                <td>${parkinguse.vname}</td>
                <td>${parkinguse.pname}</td>
                <td>${parkinguse.carNum}</td>
                <td>
                    <img src="${pageContext.request.contextPath}/images/${parkinguse.picture}" width="50" height="30" alt="">
                </td>
                <td>${parkinguse.hname}</td>
                <td>${parkinguse.telephone}</td>
                <td>
                    <c:if test="${parkinguse.type}">
                        <span class="layui-btn layui-btn-normal"> 长租 </span>
                    </c:if>

                    <c:if test="${!parkinguse.type}">
                        <span class="layui-btn layui-btn-danger"> 短租 </span>
                    </c:if>
                </td>
                <td>${parkinguse.cost}</td>
                <td><fmt:formatDate pattern="yyyy/MM/dd" value="${parkinguse.startDate}"/></td>
                <td><fmt:formatDate pattern="yyyy/MM/dd" value="${parkinguse.endDate}"/></td>
                <td><fmt:formatDate pattern="yyyy/MM/dd HH:mm:ss" value="${parkinguse.createDate}"/></td>
                <td class="td-manage">
                    <a title="编辑" href="javascript:;"
                       onclick="parkinguse_edit('编辑车位使用数据','${pageContext.request.contextPath}/parkinguse/editUi','${parkinguse.id}','1000','600')"
                       class="ml-5" style="text-decoration:none">
                        <i class="layui-icon">&#xe642;</i>
                    </a>
                    <a title="删除" href="javascript:;"
                       onclick="parkinguse_del(this,'${parkinguse.id}')"
                       style="text-decoration:none">
                        <i class="layui-icon">&#xe640;</i>
                    </a>
                </td>
            </tr>
        </c:forEach>

        </tbody>

    </table>

    <div id="page">
        <ul class="pagination">

            <li <c:if test="${pageInfo.pageNum == 1}">class="disabled"</c:if>>
                <a href="${pageContext.request.contextPath}/parkinguse/listUi?pageNum=1">&laquo;</a>
            </li>

            <%--            <li <c:if test="${pageInfo.pageNum == 1}">class="disabled"</c:if>>--%>
            <%--                <a href="${pageContext.request.contextPath}/parkinguse/listUi?pageNum=${pageInfo.pageNum-1}">&lt;</a>--%>
            <%--            </li>--%>

            <c:forEach begin="1" end="${pageInfo.pages}" var="index">
                <li <c:if test="${index == pageInfo.pageNum}">class="active"</c:if>>
                    <a href="${pageContext.request.contextPath}/parkinguse/listUi?pageNum=${index}">${index}</a>
                </li>
            </c:forEach>

            <%--            <li <c:if test="${pageInfo.pageNum == pageInfo.pages}">class="disabled"</c:if>>--%>
            <%--                <a href="${pageContext.request.contextPath}/parkinguse/listUi?pageNum=${pageInfo.pageNum+1}">&gt;</a>--%>
            <%--            </li>--%>

            <li <c:if test="${pageInfo.pageNum == pageInfo.pages}">class="disabled"</c:if>>
                <a href="${pageContext.request.contextPath}/parkinguse/listUi?pageNum=${pageInfo.pages}">&raquo;</a>
            </li>
        </ul>
    </div>

</div>

<script>
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
    });

    /*添加*/
    function parkinguse_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }

    //编辑
    function parkinguse_edit (title,url,id,w,h) {
        url = url+"?id="+id;
        x_admin_show(title,url,w,h);
    }

    /*删除*/
    function parkinguse_del(obj,id){
        layer.confirm('确认要删除吗？',{icon:3,title:'提示信息'},function(index){
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/parkinguse/delete",
                data:{id:id},
                dataType:"json",
                success:function(data){
                    //console.log(data);
                    if(data.status==1){
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg(data.info,{icon:6,time:1000});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);return false;
                    } else{
                        layer.msg(data.info,{icon:5,time:1000});return false;
                    }
                }
            });

            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }

</script>

</body>
</html>